package com.example.innovate.controller;

import com.example.innovate.bean.Result;
import com.example.innovate.domain.JobExamineDO;
import com.example.innovate.service.JobExamineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/jobExamine")
@Api(tags = "审核通知接口")
public class JobExamineController {
    @Autowired
    JobExamineService jobExamineService;

    @PostMapping("/addJobExamine")
    @ApiOperation("添加审核通知")
    public Result addJobExamine(@RequestBody JobExamineDO jobExamineDO) throws Exception{
        jobExamineService.addInfo(jobExamineDO);
        return new Result(200,"success","添加成功",jobExamineDO);
    }

    @DeleteMapping("/deleteJobExamine")
    @ApiOperation("删除审核通知")
    public Result deleteJobExamine(int id) throws Exception{
        JobExamineDO jobExamineDO = jobExamineService.findById(id);
        if(jobExamineDO!=null){
            jobExamineService.deleteInfo(id);
        }
        else{
            return new Result(400,"error","信息不存在",null);
        }
        return new Result(200,"success","删除成功",jobExamineDO);

    }

    @PostMapping("/updateJobExamine")
    @ApiOperation("修改审核通知")
    public Result updateJobExamine(@RequestBody JobExamineDO jobExamineDO) throws Exception{
        JobExamineDO jobExamineDO1 = jobExamineService.findById(jobExamineDO.getExExamineId());
        if(jobExamineDO1!=null){
            jobExamineService.updateInfo(jobExamineDO);
            return new Result(200,"success","修改成功",jobExamineDO);
        }
        else {
            return new Result(400,"error","修改信息不存在",null);
        }

    }

    @GetMapping("/findJobExamine")
    @ApiOperation("查找审核通知")
    public Result findJobExamine( @RequestParam Integer wantedId,
                                  @RequestParam Integer pageSize,
                                  @RequestParam Integer pageNumber) throws Exception{
        List<JobExamineDO> list = jobExamineService.findAll(wantedId,pageNumber,pageSize);
        return new Result(200,"success","返回成功",list);
    }
}
